import pandas as pd
import os
import time
# 读取excel1的内容到excel2
# dataFrame = pd.read_excel("D:\\WILNEVKL\\1.xlsx", sheet_name='Sheet1')
# print(dataFrame[0:3])
# dataFrame[0:3].to_excel("D:\\WILNEVKL\\22.xlsx", sheet_name='Sheet1', index=False) #从第2列开始写入
inputDir = ''
text = ''
try:
   file = open("C:\\pythonConfig.cfg")
   text = file.read()
   inputDir = text
except FileNotFoundError:
    print("默认配置文件不存在")
if text=='':
    print('空文件')
    inputDir = input("源文件夹:")
    file = open("C:\\pythonConfig.cfg", 'w')
    file.write(inputDir)
print('源文件夹', inputDir)

timed = 0.0
inputFile = ''
for root,dirs,files in os.walk(r""+inputDir):
    for file in files:
        full_path = os.path.join(root, file)
        if ('.xlsx' in full_path) or ('.xls' in full_path):
            mtime = os.stat(full_path).st_mtime
            if mtime>timed:
                timed = mtime
                inputFile = full_path
print('获取到文件：', inputFile)
outputFile = 'd:\\文件.xls'

print("输出文件：",outputFile)
# dataFrame = pd.read_excel(inputFile, sheet_name='Sheet1')
dataFrame = pd.read_excel(inputFile)
# 不要表头
# dataFrame[0:3].to_excel(outputFile, sheet_name='Sheet1', index=False ,header=False)
# 要表头
dataFrame[0:3].to_excel(outputFile, sheet_name='Sheet1', index=False ,header=True)
inputFile = input("输入任意退出:")